#!/usr/bin/env python

TEMPLATE_FILE = 'template.xml'
LIST_UNIT     = 10

import os

from google.appengine.ext import db
from google.appengine.ext import webapp
from google.appengine.ext.webapp import template
from google.appengine.ext.webapp.util import run_wsgi_app

from common.message import *


def bbody(req, user):
    control = {
        'bheader' : False,
        'bbody'   : True,
        'bfooter' : False,
    }

    hheader = { 'Content-Type' : 'text/xml; charset=utf-8' }

    params = {
        'messages' : None,
    }

    # blog
    query = db.Query(Message)
    query.filter('box = ', 'blog')
    query.filter('root_post = ', True)
    query.order('-created_date')
    params['messages'] = query.fetch(LIST_UNIT)
    for message in params['messages']:
        message.url = 'http://www.senux.com/blog/?u=%s' % message.uid
        message.content_gt120 = True if 120 < len(message.content) else False

    path  = os.path.join(os.path.dirname(__file__), TEMPLATE_FILE)
    bbody = template.render(path, params)

    return_url = None

    void = { }

    return (control, hheader, bbody, return_url, void)

